package com.zx.mes.response;

/**
 * 非集合信息返回(反回一个对象,非表返回)
 *
 * @author hyl
 * @date 2017-12-16
 */
public class ObjectRestResponse<T> extends BaseResponse {
    /**
     * T 返回的类型
     */
    private T data;

    /**
     * boolean 做为标记(看前端是否要用)
     */
    private boolean rel;

    public ObjectRestResponse() {
    }

    @Deprecated
    public ObjectRestResponse rel(boolean rel) {
        this.setRel(rel);
        return this;
    }

    @Deprecated
    public ObjectRestResponse data(T data) {
        this.setData(data);
        return this;
    }

    @Deprecated
    public ObjectRestResponse(T data, boolean rel) {
        this.data = data;
        this.rel = rel;
    }

    @Deprecated
    public ObjectRestResponse(T data, boolean rel, String message) {
        super(message);
        this.data = data;
        this.rel = rel;
    }

    /**
     * 构造函数
     *
     * @param message 返回提示消息
     * @param data    成功获取的数据
     * @param rel     失败 false 成功 true
     * @param status  根据情况返回状态
     */
    @Deprecated
    public ObjectRestResponse(T data, boolean rel, String message, Integer status) {
        super(status, message);
        this.data = data;
        this.rel = rel;
    }


    public static class Builder<T> {
        private ObjectRestResponse<T> response = new ObjectRestResponse<>();

        public Builder() {
        }

        public Builder(T data) {
            response.setData(data);
        }

        public Builder message(String message) {
            response.setMessage(message);
            return this;
        }

        public Builder rel(boolean flag) {
            response.setRel(flag);
            return this;
        }

        public Builder status(Integer status) {
            response.setStatus(status);
            return this;
        }

        public Builder<T> data(T data) {
            response.setData(data);
            return this;
        }

        public ObjectRestResponse<T> build() {
            return response;
        }
    }


    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isRel() {
        return rel;
    }

    public void setRel(boolean rel) {
        this.rel = rel;
    }
}
